<?php
namespace app\service;
use app\model\AdminModel;
use app\model\AuthGroupModel;
use think\facade\Db;
class AdminService
{
   public function login($data){
       $info=AdminModel::where('username',$data['username'])->find();
		if($info){
			if(md5(substr(md5($data['password']),0,25).'lizhili')==$info['password']){
				if($info['isopen']==1){
                    //获取是不是受限制的账号
                    $auth=AuthGroupModel::where('id',$info['role'])->find();
					session([
                        'uname'=>$info['username'],
                        'uid'=>$info['id'],
                        'userInfo'=>$info->toArray(),
                        'roleType'=>$auth['type'],
                    ]);
					return 1;//信息正确
				}else{
					return 0; //账号已经关闭
				}
			}else{
				return 0; //密码错误
			}
		}else{
			return 0;//用户名不存在
		}
	}
public function add($data){
       $data['password']=md5(substr(md5($data['password']),0,25).'lizhili');
       $res=AdminModel::create($data);
       if($res){
           return 1;//添加成功
       }else{
           return 0;//添加失败
       }
   }
}